import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from matplotlib import rcParams
from matplotlib.font_manager import FontManager
import subprocess



# mpl.rcParams['font.family'] = 'SimHei'
# plt.rcParams['axes.unicode_minus'] = False
plt.rc("font",family="Noto Sans CJK JP")
# Data
classes = ['钢珠', '玻璃碎片', '螺钉', '螺母']
heights = ['2 m', '4 cm', '8 m', 'False Positives']
values = {
    '2 m': [97, 99, 96, 96],
    '4 m': [95, 96, 93, 95],
    '8 m': [92, 94, 91, 90],
    'False Positives': [4, 3, 6, 5],
}

# Plotting
x = np.arange(len(classes))
width = 0.2

fig, ax = plt.subplots()

bar1 = ax.bar(x - width, values['2 m'], width, label='2 米')
bar2 = ax.bar(x, values['4 m'], width, label='5 米')
bar3 = ax.bar(x + width, values['8 m'], width, label='8 米')
bar4 = ax.bar(x + 2*width, values['False Positives'], width, label='虚警')

# Adding labels and title
plt.ylim(0, 110)
ax.set_xlabel('类别')
ax.set_ylabel('准确率')
ax.set_title('100次实验的检测准确率')
ax.set_xticks(x)
ax.set_xticklabels(classes)
ax.legend(loc='center right')

# Adding value labels on the bars
def add_labels(bars):
    for bar in bars:
        height = bar.get_height()
        ax.annotate('{}'.format(height),
                    xy=(bar.get_x() + bar.get_width() / 2, height),
                    xytext=(0, 4),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')

add_labels(bar1)
add_labels(bar2)
add_labels(bar3)
add_labels(bar4)

# Show plot
plt.savefig('22.png')